package com.dxiang.demo.service;

import com.alibaba.fastjson.JSONObject;
import com.dxiang.demo.mapper.GameInfoMapper;
import com.dxiang.demo.mapper.TagsMapper;
import com.dxiang.demo.model.CommonValue;
import com.dxiang.demo.model.GameInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;




@Service
public class GameInfoService {


	/**
	 * 热门榜单时间条件
	 */
	private final static int LIST_HOT = 6 * 30;
    private final Logger log = LoggerFactory.getLogger(GameInfoService.class);
    @Autowired
    private GameInfoMapper gameInfoMapper;
    @Autowired
	private GameClassificationService classificationService;
    @Autowired
    private TagService tagService;

    @Autowired
    private CommonValueService commonValueService;
    

    /**
     * 根据登陆名查询
     * @param
     * @return
     * @throws Exception
     */
	public List<GameInfo> getGameInfo() throws Exception
    {
		return gameInfoMapper.getGameInfo();
	}


	public JSONObject getHomePageGameInfo() throws Exception
    {
		JSONObject json =new JSONObject();
		
//		json.put("banner", gameInfoMapper.getGameInfoByTag("1"));
//
//		json.put("recommend", gameInfoMapper.getGameInfoByTag("2"));
//
//		json.put("weekhot", gameInfoMapper.getGameInfoByTag("3"));
		return json;
	}


	/**
	 * 获取热门榜单
	 * @return
	 */
	public List<GameInfo> getList(int time){
		return  gameInfoMapper.getGameList(time);
	}


	/**
	 * 根据游戏id获取游戏详情
	 * @param id
	 * @return
	 */
	public GameInfo getGameDetails(String id){
		return gameInfoMapper.getGameDetails(id);
	}

	/**
	 * PC 根据关键词搜索游戏
	 * @param keyWord
	 * @return
	 */
	public List<GameInfo> searchGames(String keyWord) throws Exception{
		return gameInfoMapper.searchGames(keyWord);
	}


	/**
	 * 获取游戏推荐列表
	 * @return
	 */
	public List<GameInfo> getRecommend(){
		return gameInfoMapper.getRecommend();
	}

	/**
	 * 获取新入库游戏列表
	 * @return
	 */
	public List<GameInfo> getNewList(){
		return gameInfoMapper.getNewList();
	}

	/**
	 * 获取最近更新游戏列表
	 * @return
	 */
	public List<GameInfo> getNearUpdateList(){
		return gameInfoMapper.getNearUpdateList();
	}











	/**#########################################  PC 端接口 ################################################
	 *
	 * /


	/**
	 *
	 * @return
	 * @throws Exception
	 */
	public JSONObject getPCHomePageGameInfo()throws Exception{
		JSONObject json = new JSONObject();
		json.put("recommend",gameInfoMapper.getRecommend());
		json.put("hotTags",tagService.getHotTags());
		json.put("crack",gameInfoMapper.getGameInfoByTag(33+""));
		json.put("chinesize",gameInfoMapper.getGameInfoByTag(34+""));
		json.put("btweb",gameInfoMapper.getGameInfoByTag(35+""));
		json.put("hotList",getList(LIST_HOT));
		json.put("allplay",gameInfoMapper.getGameInfo());
		return json;
	}

	/**
	 * 根据游戏分类和修改类型
	 * @param clfy  游戏分类id
	 * @param updateType  更新类型
	 * @return
	 */
	public List<GameInfo> getGameByUpdate(String clfy,String updateType){
		return gameInfoMapper.getGameByClfyAndUpdateType(clfy,updateType);
	}



	/**
	 * PC端汉化破解接口数据
	 * @param clfy
	 * @param updateType
	 * @return
	 * @throws Exception
	 */
	public JSONObject getPCCrackPage(String clfy,String updateType) throws Exception{
		JSONObject json = new JSONObject();
		json.put("list",getGameByUpdate(clfy,updateType));
		json.put("gameType",classificationService.getGameClassification());
		json.put("updateType",commonValueService.getCommonValueByParentId(clfy));
		return json;
	}

	/**
	 * PC 搜索页面数据
	 * @return
	 */
	public JSONObject searchPage(){
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("list",gameInfoMapper.searchGames(null));
		jsonObject.put("recommend",gameInfoMapper.getRecommend());
		return jsonObject;
	}


	/**
	 * PC PU主推荐页面数据
	 * @return
	 */
	public JSONObject getUpRecommand(){
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("uplist",gameInfoMapper.getRecommend());
		jsonObject.put("newList",gameInfoMapper.getNewList());
		return jsonObject;
	}

	/**
	 * 保存游戏数据
	 * @param gameInfo
	 * @return
	 */
	public int insert(GameInfo gameInfo){
		return gameInfoMapper.insert(gameInfo);
	}


/**
 *#########################################  H5端接口 ################################################
 */


	/**
	 * H5 首页数据
	 * @return
	 */
	public JSONObject h5Home(){
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("weekhot",gameInfoMapper.getGameInfo());
		jsonObject.put("recommend",gameInfoMapper.getRecommend());
		return jsonObject;
	}



}
